package us.versus.them.weeds;

import flash.display.Graphics;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.Lib;

class Vertlet {
	public var current:Point;
	public var previous:Point;
	public var force:Point;
	public var mass:Float;

	public function new( ?x:Float, ?y:Float, ?mass:Float ) {
		this.current = new Point( x, y );
		this.previous = new Point( x, y );
		this.force = new Point( 0, 0 );
		this.mass = if ( null == mass ) { 1; } else { mass; }
	}

	public function move( ?damping:Float, ?timeStep:Float ) {
		if ( 0 == damping ) damping = 1;
		if ( 0 == timeStep ) timeStep = 1;

		var x = current.x + ( current.x - previous.x ) * damping + force.x * timeStep * timeStep;
		var y = current.y + ( current.y - previous.y ) * damping + force.y * timeStep * timeStep;

		previous.x = current.x;
		previous.y = current.y;

		current.x = x;
		current.y = y;

		force.x = 0;
		force.y = 0;
	}

	public function normal() : Point {
		var normal = new Point(
			  ( current.y - previous.y )
			, ( previous.x - current.x )
		);
		normal.normalize( 1 );
		return normal;
	}
}
